package com.fxd.shopping.ware.controller;

import com.fxd.common.vo.SkuHasStockVo;
import com.fxd.core.util.PageUtils;
import com.fxd.core.util.R;
import com.fxd.core.util.RR;
import com.fxd.model.ware.WareSkuEntity;
import com.fxd.shopping.ware.service.WareSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 商品库存
 *
 * @author fuxdong
 * @email 2016335176@qqcom
 * @date 2021-07-17 12:04:42
 */
@RestController
@RequestMapping("ware/waresku")
public class WareSkuController {
    @Autowired
    private WareSkuService wareSkuService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public RR list(@RequestParam Map<String, Object> params) {
        PageUtils page = wareSkuService.queryPage(params);

        return RR.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public RR info(@PathVariable("id") Long id) {
        WareSkuEntity wareSku = wareSkuService.getById(id);

        return RR.ok().put("wareSku", wareSku);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public RR save(@RequestBody WareSkuEntity wareSku) {
        wareSkuService.save(wareSku);

        return RR.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public RR update(@RequestBody WareSkuEntity wareSku) {
        wareSkuService.updateById(wareSku);

        return RR.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public RR delete(@RequestBody Long[] ids) {
        wareSkuService.removeByIds(Arrays.asList(ids));

        return RR.ok();
    }

    @PostMapping("/has/stock")
    public R<List<SkuHasStockVo>> getSkusHasStock(@RequestBody List<Long> skuIds) {
        List<SkuHasStockVo> list = wareSkuService.getSkusHasStock(skuIds);
        return new R<>(list);
    }

}
